﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace COFE.Core.Filter
{
    public interface IOptionFilter : IFilter
    {
    }

    public static class IOptionFilterExtension
    {
        public static T FindFilter<T>(this IOptionFilter[] optionFilters)
        {
            foreach (var f in optionFilters)
                if (f is T)
                    return (T)f;
            return default(T);
        }

        public static SearchOptionEx GetSearchOption
            (this IOptionFilter[] optionFilters)
        {
            var filter = optionFilters.FindFilter<SearchOptionOptionFilter>();
            if (filter != null)
                return filter.SearchOption;
            else return SearchOptionEx.TopDirectoryOnly;
        }

        public static SearchSourceType GetSearchSource
            (this IOptionFilter[] optionFilters, 
            SearchSourceType def = SearchSourceType.All)
        {
            var filter = optionFilters.FindFilter<SearchSourceOptionFilter>();
            if (filter != null)
                return filter.SearchSource;
            else return def;
        }
    }
}
